﻿function CsvExportController($scope, service, $routeParams, $location, $http, $filter) {
    var date = new Date();
    var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
    var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
    $scope.dfrom = firstDay;
    $scope.dto = lastDay;

    $scope.month = date;
    $scope.myStore = "";
    $scope.myRadioFilter = {
        ContractType: ''
    };

    $scope.radioSelect = '1';

    $scope.isRadioSelected = function (index) {
        return index === $scope.radioSelect;
    }

    /// datepicker
    $scope.open = function ($event, opened) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope[opened] = true;
    };

    //$scope.openDayFrom = function ($event) {
    //    $event.preventDefault();
    //    $event.stopPropagation();
    //    $scope.openedDayForm = true;
    //};

    //$scope.openDayTo = function ($event) {
    //    $event.preventDefault();
    //    $event.stopPropagation();

    //    $scope.openedDayTo = true;
    //};
    $scope.dateOptions = {
        formatYear: 'yy',
        startingDay: 1
    };
    $scope.initDate = new Date('2016-15-20');
    $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM', 'dd.MM.yyyy', 'shortDate', 'yyyy/MM/dd'];
    $scope.format = $scope.formats[1];
    $scope.format2 = $scope.formats[4];
    //end
   
    //get data of Store list api/storelist/1
    $http.get(service.locationUrl + "/companystore/companyid/" + service.infoUser.Id, {})
        .success(function (data) {
            $scope.rowsStoreList = data;
        })
        .error(function (err) {

            console.log("error", err);
        });
    ///End


    $scope.update = function () {
        if ($scope.radioSelect == "1") {
            if ($scope.myStore == "") {

            }
            else {
                var objStore = {
                    CompanyId: service.infoUser.Id,
                    Name: $scope.myStore
                }
                $http.post(service.locationUrl + "/companystore/storename",
                           objStore)
                .success(function (err) {

                })
                .error(function (data) {

                    $scope.day = $filter('date')(data.ClosingTime, 'dd');
                    var month = date.getMonth() + 1;
                    var year = date.getFullYear()
                    var fullDate = String(year) + "-" + String(month) + "-" + String($scope.day);

                    console.log("StoreId", fullDate.toString('yyyy-MMM-dd'));

                    $http.get(service.locationUrl + "/worktimeofstaffs/id/" + service.infoUser.Id + "/DateForm/" + firstDay.toString('yyyy-MMM-dd') + "/DateTo/" + fullDate.toString('yyyy-MMM-dd'), {})
                    .success(function (data) {
                        $scope.staffList = data;
                    })
                    .error(function (err) {

                        console.log("error", err);
                    });
                });
            }
        }
        else {
            $scope.staffList = "";
        }
    }
        $scope.csvExport = function () {
            
        }
    }
